<template>
  <div style="padding: 20px">
    <el-card class="box-card" style="margin:0 auto;">
      <div slot="header" class="clearfix">
        <span>| 明德培训 企业注册</span>

      </div>
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="企业名称" prop="companyName">
          <el-input v-model="dataForm.companyName"/>
        </el-form-item>
        <el-form-item label="统一信用代码" prop="companyCode">
          <el-input v-model="dataForm.companyCode"/>
        </el-form-item>
        <el-form-item label="企业联系人" prop="userName">
          <el-input v-model="dataForm.userName"/>
        </el-form-item>
        <el-form-item label="企业联系人电话" prop="userPhone">
          <el-input v-model="dataForm.userPhone" type="number"/>
        </el-form-item>
        <el-form-item label="登录密码" prop="logoPasswd">
          <el-input v-model="dataForm.logoPasswd" />
        </el-form-item>
      </el-form>

      <el-button size="mini" style="margin-left:200px ; padding: 3px 0" type="primary" plain @click="createRegister">立即注册</el-button>
    </el-card>
    <!-- 添加或修改对话框 -->
    <el-dialog :visible.sync="dialogFormVisible" :close-on-click-modal="false" title="注册成功">
      <el-card class="box-card" style="margin:0 auto;">
        <div slot="header" class="clearfix">
          <span>明德培训  企业注册</span>
        </div>
        <div class="text item">
          <span>恭喜您，注册成功！</span>
        </div>
        <div class="text item">
          <span>马上开始培训之旅吧</span>
        </div>
        <el-button size="mini" style="margin-left:200px ; padding: 3px 0" type="text" @click="experience">立即体验</el-button>

      </el-card>
    </el-dialog>
  </div>
</template>

<style>
  .constant{
    width: 100%;
  }
  .img{
    margin-top: 20px;
    width: 150px;
    height: 150px;
  }
  .img img{
    width: 100%;
    height: 100%;
  }
  .list{
    width: 100%;
  }
  .list-cell{
    width: 100%;
    line-height: 50px;
  }
  .cell{
    width: 100%;
    /*display: inline-flex;*/
  }
  .set{
    color: deepskyblue;
  }
  .line{
    width: 100%;
    border-bottom: 2px solid #f6f6f6;
  }
  .erweima{
    width: 100%;
    border-bottom: 2px solid #f6f6f6;
  }
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 600px;
  }
  .line{
    width: 100%;
    border-bottom: 2px solid #f6f6f6;
  }
</style>

<script>
import { companyRegister } from '@/api/companyOperate'
import { uploadPath } from '@/api/storage'
import { getToken } from '@/utils/auth'
import Pagination from '@/components/Pagination'
import TagsView from '../layout/components/TagsView' // Secondary package based on el-pagination

export default {
  name: 'CompanyRegister',
  components: { TagsView, Pagination },
  data() {
    return {
      companyId: undefined,
      uploadPath,
      dataForm: {
        id: undefined,
        courseId: undefined,
        companyName: undefined,
        companyCode: undefined,
        companyAddress: undefined,
        logoPasswd: undefined,
        categoryName: undefined,
        userName: undefined,
        userPhone: undefined,
        categoryId: undefined,
        counselorName: undefined,
        counselorPhone: undefined,
        principalName: undefined,
        principalPhone: undefined,
        adminName: undefined,
        adminPhone: undefined,
        payPeopleNum: undefined,
        unpayPeopleNum: undefined,
        totalPeopleNum: undefined,
        totalJobPeopleNum: undefined,
        deleteMark: undefined,
        createDate: undefined

      },
      list: undefined,
      listLoading: true,
      dialogFormVisible: false,
      downloadLoading: false,
      rules: {
        companyName: [
          { required: true, message: '企业名称不能为空', trigger: 'blur' }
        ],
        companyCode: [
          { required: true, message: '企业信用代码不能为空', trigger: 'blur' }
        ],
        userName: [
          { required: true, message: '企业联系人不能为空', trigger: 'blur' }
        ],
        userPhone: [
          { required: true, message: '企业联系人电话不能为空', trigger: 'blur' }
        ],
        logoPasswd: [
          { required: true, message: '登录密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    headers() {
      return {
        'X-Litemall-Admin-Token': getToken()
      }
    }
  },
  created() {

  },
  methods: {
    resetForm() {
      this.dataForm = {
        id: undefined,
        courseId: undefined,
        companyName: undefined,
        companyCode: undefined,
        companyAddress: undefined,
        categoryName: undefined,
        logoPasswd: undefined,
        userName: undefined,
        userPhone: undefined,
        categoryId: undefined,
        counselorName: undefined,
        counselorPhone: undefined,
        principalName: undefined,
        principalPhone: undefined,
        adminName: undefined,
        adminPhone: undefined,
        payPeopleNum: undefined,
        unpayPeopleNum: undefined,
        totalPeopleNum: undefined,
        totalJobPeopleNum: undefined,
        deleteMark: undefined,
        createDate: undefined
      }
    },

    createRegister1() {
      companyRegister(this.dataForm)
        .then(response => {
          this.companyId = response.data.data.id
          this.resetForm()
          this.dialogFormVisible = true
          this.$notify.success({
            title: '成功',
            message: '创建成功'
          })
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: response.data.message
          })
        })
    },
    // createRegister() {
    //   companyRegister(this.dataForm)
    //   this.experience()
    // },
    createRegister() {
      companyRegister(this.dataForm)
        .then(response => {
          this.companyId = response.data.data.id
          this.$confirm('注册信息成功, 是否跳转首页?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.experience()
            this.$message({
              type: 'success',
              message: '跳转首页成功!'
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '跳转首页失败'
            })
          })
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: response.data.message
          })
        })
    },
    experience() {
      this.$router.push({ path: '/login' })
    }
  }
}
</script>
